﻿<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="urlwatcher" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
 <script language="CS" runat="server">
   static string sTargetUrlName = "";
   ASCIIEncoding textConverter = new ASCIIEncoding();
     
   void Page_Load(object sender, System.EventArgs e) 
   {
       sTargetUrlName = WebConfigurationManager.AppSettings["urlwatcher-target-url-parameter"];
   }
 </script>
</head>

<script runat="server">
</script>
<% 
    string sURL = Request.QueryString.ToString();
    string sRawURL = Request.RawUrl;
    string sEncodedTargetURL = Request.QueryString[sTargetUrlName];
    string sTargetURL = TokenUtils.decodeText(sEncodedTargetURL);
    string sNewTargetURL = "";
    if (sTargetURL.Contains("userid=john"))
    {
        sNewTargetURL = "hidden-target.aspx";
    }
    else if (sTargetURL.Contains("userid=matt"))
    {
        sNewTargetURL = "new-target.aspx";
    }
    else 
    {
        sNewTargetURL = "index.htm";
    }
    Response.Redirect(sNewTargetURL);
%>        
<body/>
</html>
